package com.balance.anole.client.common.handler;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.WorkbenchException;
import org.eclipse.ui.handlers.HandlerUtil;

import com.balance.anole.business.to.BusinessDateTO;
import com.balance.anole.client.common.service.CommonService;
import com.balance.anole.client.retail.view.RetailView;
import com.balance.anole.erp.perspective.Perspective;
import com.balance.anole.erp.util.ServicesCenter;

public class RetailHandler extends AbstractHandler{

	public static final String ID = RetailHandler.class.getName();

	public Object execute(ExecutionEvent event) throws ExecutionException {
		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
		CommonService cs = ServicesCenter.getServicesCenter().getService(CommonService.class);
		BusinessDateTO currentBusinessDate = cs.getBusinessDate();
		if(currentBusinessDate == null || currentBusinessDate.isLocked()){
			MessageDialog.openError(window.getShell(), "系统错误", "当前系统已锁定，不能收银.");
			return null;
		}
		RetailView view = null;
		try {
			window.getWorkbench().showPerspective(Perspective.ID, window);
			view = (RetailView) window.getActivePage().showView(RetailView.ID);

		} catch (WorkbenchException e) {
			e.printStackTrace();
		}

		return view;
	}
}
